package com.baidu.app.thread;

import java.util.List;

import org.htmlparser.Parser;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.nodes.TagNode;
import org.htmlparser.util.NodeList;

import com.baidu.app.pojo.App;
import com.baidu.app.service.AppServiceI;


public class ParserThread extends Thread {
	
	private int startPage;
	private int endPage;
	private AppServiceI service;


	

	public ParserThread(int startPage, int endPage, AppServiceI service) {
		super();
		this.startPage = startPage;
		this.endPage = endPage;
		this.service = service;
	}







	@Override
	public void run() {
		
	    try {
	    
	    	for (int i = startPage; i <= endPage; i++) {
	    
				Parser parser = new Parser("http://mm.10086.cn/android/software/qbrj?pay=1&p="+i);
				parser.setEncoding("UTF-8");
				
				HasAttributeFilter hasAttributeFilter = new HasAttributeFilter("class" ,"autoword");
				NodeList list = parser.parse(hasAttributeFilter);
				
				for (int j = 0; j < list.size(); j++) {
					String appurl = "http://mm.10086.cn" + ((TagNode)list.elementAt(j)).getAttribute("href");
					 service.addhtmlParserOne(appurl);
				}
				
			}
	    	
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		 
    }

	

	 
}
